//
//  Person.m
//  OC06_集合遍历和数组排序
//
//  Created by dllo on 15/12/8.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person
- (instancetype)initWithName:(NSString *)name
                         age:(NSInteger)age
                         sex:(NSString *)sex {
    self = [super init];
    if (self) {
        self.name = name;
        self.age = age;
        self.sex = sex;
    }
    return self;
}

- (NSComparisonResult)compareWithNameUP:(Person *)anotherPerson {
    return [self.name compare:anotherPerson.name];  
}


/** 声明一个按照name升序 #降序# 的方法. */
- (NSComparisonResult)compareWithNameDown:(Person *)anotherPerson {
    return [self.name compare:anotherPerson.name] * -1;    
}


/** 按照年龄升序 */
- (NSComparisonResult)compareWithAgeUP:(Person *)anotherPerson {
    if (self.age > anotherPerson.age) {
        return NSOrderedDescending;
    } else if (self.age < anotherPerson.age) {
        return NSOrderedAscending;
    } else {
        return NSOrderedSame;
    }
}



@end
